from threading import Thread
from core.constant import *
from core.object import LogName


class DynamicModule:
    def __init__(self, master, module: Module):
        # 实体类基础属性
        self.master = master
        self.engine = None
        self.module: Module = module

    def task_start(self):
        module = self.master.file_manager.now_dynamic_module
        if self.master.file_manager.now_dynamic_module in self.master.file_manager.run_status.run_module_ls:
            info = f"[{self.module.value}]模块有正在运行的任务。"
            self.master.file_manager.log_engine.emit(info, LogName.Operate)
            return False
        else:
            info = f"[{self.module.value}]任务开始。\n**请勿在任务期间更改参数，避免未知错误！"
            self.master.file_manager.log_engine.emit(info, LogName.Operate)

            self.master.file_manager.run_status.start_task(module)
            return True

    def task_end(self):
        module = self.master.file_manager.now_dynamic_module
        info = f"[{self.module.value}]任务结束。"
        self.master.file_manager.log_engine.emit(info, LogName.Operate)

        self.master.file_manager.run_status.end_task(module)
        return True

    def on_run(self):
        is_true = self.task_start()
        if is_true:
            pass
        else:
            return
        # 输出操作日志至界面
        info = f"[{self.module.value}]执行[{ButtonMember.Run.value}]方法。"
        self.master.file_manager.log_engine.emit(info, LogName.Operate)

        # 点击运行按钮回调
        thread = Thread(target=self.on_run_thread)
        thread.start()
        pass

    def on_run_thread(self):
        pass

    def on_ok(self):
        is_true = self.task_start()
        if is_true:
            pass
        else:
            return
        # 输出操作日志至界面
        info = f"[{self.module.value}]执行[{ButtonMember.Ok.value}]方法。"
        self.master.file_manager.log_engine.emit(info, LogName.Operate)
        # 点击运行按钮回调
        thread = Thread(target=self.on_ok_thread)
        thread.start()
        pass

    def on_ok_thread(self):
        pass

    def on_only_data(self):
        is_true = self.task_start()
        if is_true:
            pass
        else:
            return
        # 输出操作日志至界面
        info = f"[{self.module.value}]执行[{ButtonMember.OnlyData.value}]方法。"
        self.master.file_manager.log_engine.emit(info, LogName.Operate)
        thread = Thread(target=self.on_only_data_thread)
        thread.start()

    def on_only_report(self):
        is_true = self.task_start()
        if is_true:
            pass
        else:
            return
        # 输出操作日志至界面
        info = f"[{self.module.value}]执行[{ButtonMember.OnlyReport.value}]方法。"
        self.master.file_manager.log_engine.emit(info, LogName.Operate)
        thread = Thread(target=self.on_only_report_thread)
        thread.start()

    def on_only_report_thread(self):
        pass

    def on_stop(self):
        pass


class AdditionModule:
    def __init__(self, master, module: Module):
        # 实体类基础属性
        self.master = master
        self.module = module

    def on_ok(self):
        pass

    def on_run(self):
        pass

    def on_draw(self):
        pass

